package models

import (
	"github.com/jinzhu/gorm"
	"kop/modules/quest/entity"
)

func AutoMigrate(dB *gorm.DB) {

	dB.AutoMigrate(new(entity.Quest))
	dB.AutoMigrate(new(entity.DailyQuest))
	//dB.AutoMigrate(new(entity.Login))
}

func GetQuest(dB *gorm.DB, roleID int32) entity.Quest {

	var quest = entity.Quest{
		RoleID:  roleID,
		QuestID: 1,
	}

	if err := dB.FirstOrCreate(&quest).Error; err != nil {
		panic(err)
	}

	return quest
}

func Save(dB *gorm.DB, quest *entity.Quest) {

	if err := dB.Save(quest).Error; err != nil {
		panic(err)
	}
}
